<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ImageShow
 *
 * @author hodek
 */
include  'admin/Util.php';




$link = Util::getLink();

$query = sprintf(Util::$select_jornakImages,
    mysql_real_escape_string($_GET["id"])
);

$result = mysql_query($query);

if (!$result) {
    die('Could not query:' . mysql_error());
}

while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
    $db_img = $row['full'];
    $width = $row['width'];
    $height = $row['height'];
    $type = $row['ext'];
}

$db_img = base64_decode($db_img);

if ($_GET["tn"]) {        
    switch ($type) {
        case "jpg":
            header("Content-Type: image/jpeg");
            break;
        case "jpeg":
            header("Content-Type: image/jpeg");
            break;
        case "gif":
            header("Content-Type: image/gif");
            break;
        case "png":
            header("Content-Type: image/png");
            break;
    }
    $image_p = imagecreatetruecolor(137, 84);
    $db_img = imagecreatefromstring($db_img);
    imagecopyresampled($image_p, $db_img, 0, 0, 0, 0, 137, 84, $width, $height);
    imagejpeg($image_p);
}else {
    $db_img = imagecreatefromstring($db_img);
    if ($db_img !== false) {
        switch ($type) {
            case "jpg":
                header("Content-Type: image/jpeg");
                imagejpeg($db_img);
                break;
            case "jpeg":
                header("Content-Type: image/jpeg");
                imagejpeg($db_img);
                break;
            case "gif":
                header("Content-Type: image/gif");
                imagegif($db_img);
                break;
            case "png":
                header("Content-Type: image/png");
                imagepng($db_img);
                break;
        }
    }
}

Util::closeLink($link);
imagedestroy($db_img);
?>
